package com.lovetemperature.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.lovetemperature.dao.Dao;
import com.lovetemperature.model.Good;
import com.lovetemperature.model.GoodCategory;
import com.lovetemperature.model.GoodSet;
import com.lovetemperature.service.GoodService;

public class GoodServiceImpl implements GoodService{
	private Dao<Good> goodDao;
	private Dao<GoodSet> goodSetDao;
	
	@Override
	public List<GoodSet> findAllDanGao() {
		return goodSetDao.findByField("good.category", GoodCategory.蛋糕.toString());
	}

	@Override
	public boolean addGood(Good good) {
		goodDao.save(good);
		return true;
	}

	@Override
	public List<String> findGoodCategory() {
		List<String> categories = new ArrayList<String>();
		for(GoodCategory one : GoodCategory.values()){
			categories.add(one.toString());
		}
		return categories;
	}

	public Dao<Good> getGoodDao() {
		return goodDao;
	}

	public void setGoodDao(Dao<Good> goodDao) {
		this.goodDao = goodDao;
	}

	@Override
	public List<GoodSet> findAllMianBao() {
		return goodSetDao.findByField("good.category", GoodCategory.面包.toString());
	}

	@Override
	public List<GoodSet> findAllGanDian() {
		return goodSetDao.findByField("good.category", GoodCategory.干点.toString());
	}

	@Override
	public List<GoodSet> findAllBanShouLi() {
		return goodSetDao.findByField("good.category", GoodCategory.拌手礼.toString());
	}

	@Override
	public List<GoodSet> findAllYinPin() {
		return goodSetDao.findByField("good.category", GoodCategory.饮品.toString());
	}

	@Override
	public List<GoodSet> findAllQiTa() {
		return goodSetDao.findByField("good.category", GoodCategory.其他.toString());
	}

	@Override
	public Good findById(Long goodId) {
		return goodDao.findById(goodId);
	}

	@Override
	public void update(Good good) {
		goodDao.update(good);
	}

	public Dao<GoodSet> getGoodSetDao() {
		return goodSetDao;
	}

	public void setGoodSetDao(Dao<GoodSet> goodSetDao) {
		this.goodSetDao = goodSetDao;
	}
}
